package com.wgw.first.user.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wgw.first.R;
import com.wgw.first.user.bean.OrderBean2;
import com.wgw.first.utils.Constants;

import java.util.List;

/**
 * @author Admin
 * @version $Rev$
 * @des ${TODO}
 * @updateAuthor $Author$
 * @updateDes ${TODO}
 */
public class OrderAdapter extends BaseAdapter {

    private Context mcontext;
    private List<OrderBean2.Order> orders;

    public OrderAdapter(List<OrderBean2.Order> orders,Context context){
        this.orders = orders;
        this.mcontext = context;
    }

    @Override
    public int getCount() {
        return orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = View.inflate(mcontext, R.layout.item_order,null);
        OrderBean2.Order order = (OrderBean2.Order) getItem(position);

        ImageView iv_gov = (ImageView)v.findViewById(R.id.iv_gov);
        TextView  tv_desc_gov = (TextView)v.findViewById(R.id.tv_desc_gov);
        TextView  tv_address = (TextView)v.findViewById(R.id.tv_address);
        TextView  tv_phone = (TextView)v.findViewById(R.id.tv_phone);
        TextView  tv_count = (TextView)v.findViewById(R.id.tv_total_number);
        TextView  tv_totalprice = (TextView)v.findViewById(R.id.tv_totalprice);
        TextView  tv_date = (TextView)v.findViewById(R.id.tv_date);
        Glide.with(mcontext)
                .load(Constants.BASE+Constants.IMG+order.getImgUrl())
                .into(iv_gov);

        tv_desc_gov.setText(order.getBook_name());
        tv_address.setText("地址："+order.getAddress());
        tv_phone.setText("电话："+order.getPhone());
        tv_count.setText("数量：" + order.getNumber());
        tv_totalprice.setText("￥" + order.getTotal_price());
        tv_date.setText("下单时间:"+order.getDate());


        return v;
    }
}
